using com.youzu.got.protocol;
using CastSkill = com.youzu.warh.protocol.CastSkill;
using EffectElement = com.youzu.warh.protocol.EffectElement;

namespace Yoozoo.Gameplay.RTS
{
    /// <summary>
    /// 技能特效额外拆开的一个分部类
    /// </summary>
    public partial class RoundFightPlayer
    {
        /// <summary>
        /// 技能来源
        /// </summary>
        public enum SkillAuthorType
        {
            None = 0, //未知来源
            March = 1, //部队技能
            Equipment = 2,//装备技能
            CarSkill = 3,//豪车技能
        }
        
        /// <summary>
        /// 检查是否加入不需要依赖heroId的技能特效
        /// 如豪车
        /// </summary>
        private void CheckNormalSkillEffect(MarchEntity marchEntity,CastSkill skill,float startTime)
        {
            //豪车一类的
            var target = marchEntity.GetBattleTarget();
            bool play = true;

            bool canPlaySkill = GetSkillCurrentNum() < RTSQualityHelper.MaxSkillEffectNum || RTSQualityHelper.MaxSkillEffectNum == -1;
            bool limitSelf = RTSQualityHelper.LimitSelfTroop;
            bool RelateSelf = marchEntity.Team == MarchHelper.TeamSelf ||
                              (target != null && target.Team == MarchHelper.TeamSelf);

            //检测飘字数量限制
            if (!canPlaySkill)
            {
                if (RelateSelf)
                {
                    if (limitSelf)
                    {
                        play = false;
                    }
                }
                else
                {
                    play = false;
                }
            }
            //豪车技能 忽略数量限制
            var skillConfig = _rtsResMgr.GetHeroSkillConfig(skill.skillId, skill.skillLv);
            if(skillConfig?.author_type == 3)
            {
                play = true;
            }
            //如果刚脱战，则不播
            if ((target != null && target.MarchInfo.isJustLeaveBattle))
            {
                play = false;
            }
            if (play)
            {
                
                if (skillConfig.author_type == 3 && skillConfig.skill_effect_id.Count > 0)
                {
                    AddSkill(skill, 0, marchEntity, startTime);
                }
                //豪车技能是否播放瓢字?
                RegistFlyTextInfo(skillFlyTextTable, skill, marchEntity.Tid, (com.youzu.warh.protocol.TargetCoordinateType)marchEntity.TargetCoordinateType);
            }
        }
        
        /// <summary>
        /// 思考,
        /// 原本的技能会走技能的逻辑
        /// </summary>
        private void CheckPlayCarSkillElementEffect(MarchEntity marchEntity,float startTime,EffectElement effectElement)
        {
            //1. 显示特效需要依赖到目标部队
            //2. 目标部队需要加一个脏依赖,销毁时需要干掉
            //normal
            var elementConfig = ArmyManager.Instance.ResourceManager.GetSkillElementRtsConfig(effectElement.elementId);
            if (elementConfig != null && elementConfig.skill_effect_id[0]>0)
            {
                var skillHit = marchEntity.GetCarSkill();
                if (skillHit!=null)
                {
                    //延长时间
                    skillHit.ResetSkillTimer();
                }
                else
                {
                    skillHit = RTSClassPoolManager.GetSkillHit();
                    skillHit.Initialize(effectElement, marchEntity, startTime, marchEntity.GetBattleTarget(), elementConfig.float_text_type,true);
                    skillHitList.Add(skillHit);
                    marchEntity.SetCarSkill(skillHit);
                }
            }
        }
        
    }
}
